#include "headfile.h"

struct encoder_state encoder;

void encode_diff_change(struct encoder_state *encoder,int16_t diff)
{
	diff = diff > 5 ? 5:diff;
	diff = diff < -5 ? -5:diff;
	encoder->diff+=diff;
	encoder->diff = encoder->diff > 10 ? 10:encoder->diff;
	encoder->diff = encoder->diff < -10 ? -10:encoder->diff;
	encoder->data_state = 1;
}

void encode_pressed_change(struct encoder_state *encoder,uint8_t press)
{
	encoder->pressed = press;
	encoder->data_state = 1;
}

int8_t get_encde_diff(struct encoder_state *encoder)
{
	
	if(encoder->data_state)
	{
		int8_t diff = encoder->diff;
		encoder->diff = 0;
		encoder->data_state = 0;
		return diff;
	}
	else
	{
		return 0;
	}
}

int8_t get_encode_press(struct encoder_state *encoder)
{
	uint8_t press = encoder->pressed;
	return press;
}

















